package tetramage.nuclearmayhem.worldgen;

import java.util.Random;

import net.minecraft.block.Block;
import net.minecraft.world.World;
import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.feature.WorldGenMinable;
import tetramage.nuclearmayhem.common.NuclearMayhem;
import cpw.mods.fml.common.IWorldGenerator;

public class NuclearMayhemWorldGen implements IWorldGenerator {

	@Override
	public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) {
	switch(world.provider.dimensionId) {
	case 0 :
		//Generate our surface world in minecraft
		generateSurface(world, random, chunkX*16, chunkZ*16);
		
	case -1 :
		//Generate our surface world
		generateNether(world, random, chunkX*16, chunkZ*16);
		
	case 1 :
		//Generate our surface world
		generateEnd(world, random, chunkX*16, chunkZ*16);
	}
		
	}
	
	private void generateSurface(World world, Random random, int x, int z) {
		//this.addOreSpawn(NuclearMayhem.Ore , world, random, i-blockXPos, j- blockZPos, maxVeinSize, chancetospawn, minY, maxY);
		this.addOreSpawn(NuclearMayhem.CopperOre, world, random, x, z, 16, 16, 4+random.nextInt(6), 45, 5, 100);
		this.addOreSpawn(NuclearMayhem.LeadOre, world, random, x , z, 16, 16, 4+random.nextInt(6), 50, 5, 40);
		this.addOreSpawn(NuclearMayhem.SilverOre, world, random, x, z, 16, 16, 4+random.nextInt(6), 25, 5, 10);
		this.addOreSpawn(NuclearMayhem.ZincOre, world, random, x, z, 16, 16, 4+random.nextInt(6), 25, 5, 10);
	}
	
	

	private void generateNether(World world, Random random, int x, int z) {
		
	}

	private void generateEnd(World world, Random random, int x, int z) {
		
	}
	
	private void addOreSpawn(Block block, World world, Random random, int blockXPos, int blockZPos, int maxX, int maxZ, int maxVeinSize, int chanceToSpawn, int minY, int maxY) {
		for(int i = 0; i < chanceToSpawn; i++) {
			int posX = blockXPos + random.nextInt(maxX);
			int posY = minY + random.nextInt(maxY - minY);
			int posZ = blockZPos + random.nextInt(maxZ);
			(new WorldGenMinable(block, maxVeinSize)).generate(world, random, posX, posY, posZ);
			
		}
	}

	

	

}
